package com.zb.network.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjNetworkEmpFieldService;
import com.zb.utils.TokenUtil;
import com.zb.vo.NetworkFieldVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 网点人员字段表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-10-18
 */
@Api(tags = "服务商人员字段类接口")
@RestController
@RequestMapping("/network/emp/field")
public class ZjNetworkEmpFieldController {
    @Resource
    private ZjNetworkEmpFieldService networkEmpFieldService;

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "服务区域-服务商设置-服务商人员字段 - 新增或修改服务商人员自定义字段")
    @ApiOperation("新增或修改服务商人员自定义字段")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid NetworkFieldVo networkFieldVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        networkEmpFieldService.save(custAccId, networkFieldVo);
        return Result.success(null == networkFieldVo.getId()? "新增字段成功" : "修改字段成功");
    }

    @ApiOperation("获取服务商人员字段列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取服务商字段列表成功").data(networkEmpFieldService.getList(custAccId, selectVo));
    }

    @ApiOperation("获取服务商人员字段详情")
    @PostMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "字段ID", required = true) Long id) {
        return Result.success("获取服务商字段详情成功").data("row", networkEmpFieldService.getDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商设置-服务商人员字段 - 批量启用或禁用服务商人员字段")
    @ApiOperation("批量启用或禁用服务商人员字段")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "字段状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "字段ID集合", required = true) List<Long> ids) {
        networkEmpFieldService.updateDisableBatchById(ids, status);
        return Result.success(status? "禁用字段成功" : "启用字段成功");
    }
    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商设置-服务商人员字段 - 批量更改移动端隐藏或显示服务商人员字段")
    @ApiOperation("批量更改移动端隐藏或显示服务商人员字段")
    @PutMapping("/mobileShow")
    public Result mobileShow(@RequestParam @ApiParam(value = "是否移动端显示：false-隐藏，true-显示", required = true, example = "true") boolean mobileShow,
                             @RequestBody @ApiParam(value = "字段ID集合", required = true) List<Long> ids) {
        networkEmpFieldService.updateMobileShowBatchById(ids, mobileShow);
        return Result.success(mobileShow? "更改移动端字段显示成功" : "更改移动端字段隐藏成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.DELETE, remark = "服务区域-服务商设置-服务商人员字段 - 批量删除服务商人员字段")
    @ApiOperation("批量删除服务商人员字段")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "字段ID集合", required = true) List<Long> ids) {
        networkEmpFieldService.deleteBatchById(ids);
        return Result.success("删除字段成功");
    }

}
